<template>
  <div>
    <div>
      <el-input value=""placeholder="设备id" type="text" style="width:auto" v-model="deviceId"></el-input>
      <el-input value=""placeholder="code" type="text" style="width:auto"  v-model="thecode"></el-input> <br/><br/>
      <el-button @click="debugOpen()" ref="more" type="info">连接</el-button>
      <el-button @click="debugClose()" ref="more" type="info">关闭</el-button>
      <el-button @click="debugSeeId()" ref="more" type="info">查看</el-button>
      <el-button @click="debugClearReady()" ref="more" type="info">清理</el-button>
      <el-button @click="debugClear()" v-show="sureShow" ref="more" type="info">确认清理</el-button>
      <el-button @click="debugClearVoice()" v-show="sureShow" ref="more" type="info">确认清理声音文件</el-button>
      <br/><br/>
      <el-input value="" placeholder="日志文件名" style="width:auto" v-model="logfile"></el-input>
      <el-button @click="debugGetLog()" ref="more" type="info">获取日志</el-button>
      <div id="text-result">{{ result }}</div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import {UseUrl} from "../../utils/config";
import * as utils from "../../utils/utils"

export default {
  name: "yqdebug",
  data() {
    return {
      deviceId:"",
      logfile:"",
      result:"",
      thecode:"",
      sureShow: false
    }
  },
  methods: {
    debugOpen: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteOpen';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
      }).catch((error => {
        console.log(error);
        this.result = error;
      }))
    },
    debugClose: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteClose';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
      }).catch((error => {
        console.log(error);
        this.result = error;
      }))
    },
    debugSeeId: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteSeeId';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
      }).catch((error => {
        console.log(error);
        this.result = error;
      }))
    },
    debugGetLog: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteGetFile';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
      }).catch((error => {
        console.log(error);
        this.result = error;
      }))
    },
    debugClearReady: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请确认";
      this.sureShow = true;
    },
    debugClear: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteClear';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
        this.sureShow = false;
      }).catch((error => {
        console.log(error);
        this.result = error;
        this.sureShow = false;
      }))
    },
    debugClearVoice: function() {
      var id = this.deviceId;
      var file = this.logfile;
      var that = this;
      this.result = "请求中...";
      var params = {};
      params['id'] = id;
      params['cmd'] = 'remoteClearVoice';
      params['code'] = this.thecode;
      params['fileName'] = file;
      Vue.axios.post(UseUrl + "/debug/yqsl", JSON.stringify(params),
          {headers:{'Content-Type':'application/json; charset=utf-8'}}
      ).then((response) => {
        that.result = response.data;
        this.sureShow = false;
      }).catch((error => {
        console.log(error);
        this.result = error;
        this.sureShow = false;
      }))
    }
  },
  mounted() {
    // this.$refs.more.$el.click();
  },
  beforeCreate () {

  }
}
</script>

<style scoped>
div {
  text-align: center;
}
#text-result{
  border:  2px aliceblue;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.time {
  color: gray;
}
</style>
